package com.bskj.bms.quartz;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.bskj.bms.Utils.MailService;
import com.bskj.common.bean.model.ParkInInfo;
import com.bskj.common.bean.model.ParkInfo;
import com.bskj.common.bean.model.ParkingLotCustomer;
import com.bskj.common.dao.ParkInInfoDao;
import com.bskj.common.dao.ParkInfoDao;
import com.bskj.common.dao.ParkingLotCustomerDao;
import com.bskj.common.dao.core.FindRequestEntity;
import com.bskj.common.dao.core.WhereEnum;

public class SendEmail {
	private ParkInfoDao parkInfoDao;
	private ParkInInfoDao parkInInfoDao;
	private ParkingLotCustomerDao parkingLotCustomerDao;

	public ParkInfoDao getParkInfoDao() {
		return parkInfoDao;
	}

	public void setParkInfoDao(ParkInfoDao parkInfoDao) {
		this.parkInfoDao = parkInfoDao;
	}

	public ParkInInfoDao getParkInInfoDao() {
		return parkInInfoDao;
	}

	public void setParkInInfoDao(ParkInInfoDao parkInInfoDao) {
		this.parkInInfoDao = parkInInfoDao;
	}

	public ParkingLotCustomerDao getParkingLotCustomerDao() {
		return parkingLotCustomerDao;
	}

	public void setParkingLotCustomerDao(ParkingLotCustomerDao parkingLotCustomerDao) {
		this.parkingLotCustomerDao = parkingLotCustomerDao;
	}

	public void sendEmails() {
		int time = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
		if (7 < time && time < 22) {
			FindRequestEntity findReq = new FindRequestEntity();
			try {
				findReq.addWhere("is_remind", WhereEnum.EQ, 1);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			List<ParkingLotCustomer> parkingLotCustomerList = parkingLotCustomerDao.find(findReq);
			if (parkingLotCustomerList == null || parkingLotCustomerList.size() == 0) {
			} else {
				for (ParkingLotCustomer parkingLotCustomer : parkingLotCustomerList) {
					FindRequestEntity findReqs = new FindRequestEntity();
					try {
						long t = System.currentTimeMillis() - 30 * 60 * 1000;
						Date date = new Date(t);
						if (parkingLotCustomer.getId() != null) {
							findReqs.addWhere("park_lot_custimer_id", WhereEnum.EQ, parkingLotCustomer.getId());
						}
						findReqs.addWhere("create_time", WhereEnum.GT, date);
						List<ParkInfo> parkInfos = parkInfoDao.find(findReqs);
						List<ParkInInfo> parkInInfos = parkInInfoDao.find(findReqs);
						if ((parkInfos == null || parkInfos.size() == 0)
								&& (parkInInfos == null || parkInInfos.size() == 0)) {
							MailService.sendHtmlMail(parkingLotCustomer.getName());
						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
	}

}
